/*
 * Copyright (C) 2011 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_AllocateErr.java
 *
 * Created on 31/08/2011, 10:41:23
 */
package kuasar.plugin.deployer.gui.actions.dialogs;

import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import kuasar.plugin.Intercom.GUI;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_AllocateErr extends kuasar.plugin.classMod.AbstractPanel {
    private ArrayList<String[]> errors;
    private DefaultListModel model = new DefaultListModel();
    private JPanel first;
    /** Creates new form pn_AllocateErr */
    public pn_AllocateErr(ArrayList<String[]> errors, JPanel first) {
        this.first = first;
        this.errors = errors;
        initComponents();
        loadErrors();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        spn_Errors = new javax.swing.JScrollPane();
        lst_Errors = new javax.swing.JList();
        btn_Abortar = new javax.swing.JButton();
        lbl_Info = new kuasar.plugin.deployer.gui.classmod.JMarqueeLabel();

        setOpaque(false);

        lst_Errors.setModel(model);
        lst_Errors.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lst_ErrorsValueChanged(evt);
            }
        });
        spn_Errors.setViewportView(lst_Errors);

        btn_Abortar.setBackground(new java.awt.Color(0, 0, 0));
        btn_Abortar.setForeground(new java.awt.Color(204, 204, 204));
        btn_Abortar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/abort16.png"))); // NOI18N
        btn_Abortar.setText("Abort");
        btn_Abortar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AbortarActionPerformed(evt);
            }
        });

        lbl_Info.setForeground(new java.awt.Color(204, 204, 204));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_Info, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
                    .addComponent(spn_Errors, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
                    .addComponent(btn_Abortar, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(spn_Errors, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_Info, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(btn_Abortar)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void lst_ErrorsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lst_ErrorsValueChanged
    if(!evt.getValueIsAdjusting())
        loadErrorDesc();
    
}//GEN-LAST:event_lst_ErrorsValueChanged

private void btn_AbortarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AbortarActionPerformed
    GUI.loadPlugin(first);
    GUI.updateUI();
}//GEN-LAST:event_btn_AbortarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Abortar;
    private javax.swing.JLabel lbl_Info;
    private javax.swing.JList lst_Errors;
    private javax.swing.JScrollPane spn_Errors;
    // End of variables declaration//GEN-END:variables

    private void loadErrorDesc(){
        lbl_Info.setText(errors.get(lst_Errors.getSelectedIndex())[2]);
    }
    
    private void loadErrors() {
        for(String[] error : errors){
            model.addElement(error[1]);
        }
    }
    
}
